package operation;

import book.Book;
import book.BookList;

import java.util.Scanner;

public class AddOperation implements IOPeration {

    @Override
    public void work(BookList bookList) {
        System.out.println("新增图书");
        Scanner scanner = new Scanner(System.in);

        System.out.println("请输入您新增图书的书名:");
        String bookName = scanner.nextLine();

        System.out.println("请输入您新增图书的作者:");
        String bookAuthor = scanner.nextLine();

        System.out.println("请输入您新增图书的类型:");
        String bookType = scanner.nextLine();

        System.out.println("请输入您新增图书的价格:");
        int bookPrice = scanner.nextInt();


        Book book1 = new Book(bookName,bookAuthor,bookPrice,bookType);
       // String name = scanner.nextLine();
        int currentSize = bookList.getUsedSize();
        for (int i = 0; i <currentSize; i++) {
            Book book2 = bookList.getBook(i);
            if (book2.getBookName().equals(bookName)) {
                System.out.println("这本书已存在,不能重复添加");

                return;
            }

        }
        bookList.setBooks(currentSize,book1);
        bookList.setUsedSize(currentSize + 1);
    }
}
